Now that we know much more about how system and devices are working togeder lets talk about kernel modules

lsmod, modprobe, insmod, rmmod

In [6]:
# list modules loaded into kernel
# /proc/modules
lsmod | head
Module                  Size  Used by
vboxpci                24576  0
uas                    24576  0
usb_storage            69632  2 uas
msr                    16384  0
acpi_call              16384  0
pci_stub               16384  1
vboxnetadp             28672  0
vboxnetflt             28672  0
vboxdrv               454656  3 vboxnetadp,vboxnetflt,vboxpci
In [11]:
cat /proc/modules | grep -i vbox
vboxpci 24576 0 - Live 0x0000000000000000 (OE)
vboxnetadp 28672 0 - Live 0x0000000000000000 (OE)
vboxnetflt 28672 0 - Live 0x0000000000000000 (OE)
vboxdrv 454656 3 vboxpci,vboxnetadp,vboxnetflt, Live 0x0000000000000000 (OE)
In [3]:
lsmod | grep -i vboxpci
vboxpci                24576  0
vboxdrv               454656  3 vboxnetadp,vboxnetflt,vboxpci
In [ ]:
# Remove a module
modprobe -r vboxpci
rmmod vboxpci
In [ ]:
# Load a  module
modprobe modulenName
insmod full-Path-to-module
In [7]:
# get module info
modinfo vboxpci
filename:       /lib/modules/4.4.0-57-generic/updates/dkms/vboxpci.ko
version:        5.0.24_Ubuntu r108355
license:        GPL
description:    Oracle VM VirtualBox PCI access Driver
author:         Oracle Corporation
srcversion:     3B78BC57F16249D1EF8D255
depends:        vboxdrv
vermagic:       4.4.0-57-generic SMP mod_unload modversions 
In [ ]:
# load vboxpci with insmod and full path
insmod /lib/modules/4.4.0-53-generic/updates/dkms/vboxpci.ko
In [8]:
# show dependencies of a module
modprobe --show-depends vboxpci
insmod /lib/modules/4.4.0-57-generic/updates/dkms/vboxdrv.ko 
insmod /lib/modules/4.4.0-57-generic/updates/dkms/vboxpci.ko 

So if I load vboxpci then vboxdrv also will be loaded
The process at remove is the same.

lsusb

In [14]:
whatis lsusb
whatis lspci
lsusb (8)            - list USB devices
lspci (8)            - list all PCI devices
In [13]:
lsusb
Bus 002 Device 002: ID 8087:8000 Intel Corp. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 5986:0397 Acer, Inc 
Bus 003 Device 006: ID 1000:1320 Speed Tech Corp. 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
In [16]:
lsusb -t # dump hierarchy as a tree
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
    |__ Port 1: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 480M
    |__ Port 12: Dev 2, If 0, Class=Video, Driver=uvcvideo, 480M
    |__ Port 12: Dev 2, If 1, Class=Video, Driver=uvcvideo, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
In [18]:
# check bus 003
lsusb -s 003:
Bus 003 Device 002: ID 5986:0397 Acer, Inc 
Bus 003 Device 006: ID 1000:1320 Speed Tech Corp. 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
In [19]:
# bus 003 device 006
lsusb -s 003:006
Bus 003 Device 006: ID 1000:1320 Speed Tech Corp. 
In [22]:
# USB with vendor id: 1000 and device id: 1320
lsusb -d 1000:1320
Bus 003 Device 006: ID 1000:1320 Speed Tech Corp. 

There is a list of all knowen usb vendor and products:

/var/lib/usbutils/usb.idsDownload new daily snapshot of list: sudo update-usbids
In [23]:
lsusb | sort | cut -d ' ' -f1-2 | uniq
Bus 001
Bus 002
Bus 003
Bus 004

lspci

In [25]:
# vendor code
lspci -n | head -2
00:00.0 0600: 8086:0c04 (rev 06)
00:02.0 0300: 8086:0416 (rev 06)
In [27]:
# name and code of vendor
lspci -nn | head -2
00:00.0 Host bridge [0600]: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller [8086:0c04] (rev 06)
00:02.0 VGA compatible controller [0300]: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller [8086:0416] (rev 06)
In [33]:
# lspci -vvv (verbose to three times)
In [46]:
# lspci -d [<vendor>]:[<device>][:<class>]
lspci -d 8086:0416:0300
00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
lspci -s [[[[]:]]:][][.[]] Example only contais slot and function:
In [53]:
lspci -s :02.0
00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
In [54]:
# domain, bus, slot, func
lspci -s 00:04:00.0

# bus, slot, func
lspci -s 04:00.0
04:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter
04:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter
In [58]:
# slot
lspci -s 00 | head -2
00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller (rev 06)
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5227 PCI Express Card Reader (rev 01)
In [57]:
# which kernel is in charge of handeling the device
lspci -k | grep -i vga -A3
00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
	Subsystem: Lenovo 4th Gen Core Processor Integrated Graphics Controller
	Kernel driver in use: i915
	Kernel modules: i915
A list of all known PCI ID's:
/usr/share/hwdata/pci.idssudo update-pciids

use another file instead of pci.ids:

In [ ]:
lspci -i [file]

Exercise:

Change VGA details to firefox by mozilla foundation

Explainations:

  • A PCI device can have up to eight functions
  • The revision number defines the device's chipset and firmware versions
In [66]:
# lspci -vmm  # machine readable
# lspci -x    # hexadecimal

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github